package longrise.phone.com.bjjt_henan.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.longrise.LEAP.Base.Objects.EntityBean;

import longrise.phone.com.bjjt_henan.R;
import longrise.phone.com.bjjt_henan.Utils.CommontUtils;
import longrise.phone.com.bjjt_henan.widget.WeacherDialog;

/**
 * 未来天气适配器
 * Created by Administrator on 2017/4/19.
 */
public class WeacherAdapter extends BaseAdapter {

    private Context mContext;

    private EntityBean[] lists;

    public WeacherAdapter(Context context) {
        this.mContext = context;
    }

    public void setLists(EntityBean[] lists) {
        this.lists = lists;
    }

    @Override
    public int getCount() {
        return (lists == null) ? 0 : lists.length - 1;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (null == convertView) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.adapter_weacher_item, null);
            holder.dayTV = (TextView) convertView.findViewById(R.id.weacher_item_day);
            holder.iconTV = (ImageView) convertView.findViewById(R.id.weacher_item_icon);
            holder.weaTV = (TextView) convertView.findViewById(R.id.weacher_item_wea);
            holder.tempTV = (TextView) convertView.findViewById(R.id.weacher_item_temp);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        EntityBean bean = lists[position + 1];
        holder.dayTV.setText(bean.getString("date"));
        String weacher = bean.getString("weather");
        holder.iconTV.setBackgroundResource(CommontUtils.getWeacherIcon(weacher));
        holder.weaTV.setText(weacher);
        holder.tempTV.setText(WeacherDialog.getWeacherStr(bean.getString("temperature")));

        return convertView;
    }

    private class ViewHolder {
        private TextView dayTV;
        private ImageView iconTV;
        private TextView weaTV;
        private TextView tempTV;
    }
}
